public class Solution1 {

    int[] nums;
    int i;
    public Solution1(ListNode head) {
        nums = new int[10001];
        i = 0;
        while (head != null) {
            nums[i++] = head.val;
            head = head.next;
        }
    }

    public int getRandom() {
        return nums[(int) (Math.random() * i)];
    }
}
